home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / ShowAndSaveGWorld.c < prev    next >
Text File  |  1995-07-20  |  3KB  |  100 lines

  1. /*
  2. ShowAndSaveGWorld.c
  3.  
  4. This shows a GWorld image on the selected device and saves it to disk as a PICT or eps file.
  5. I find it useful when preparing images for demos, etc.
  6.  
  7. The image is displayed on-screen in the supplied size. However, before saving to
  8. disk it is expanded by the "expand" factor.
  9.  
  10. Here are the bare bones of a program to use ShowAndSaveGWorld:
  11.  
  12.     int screen=1,savePICT=0,saveEPS=1;
  13.     GDHandle device;
  14.     double expand=2;
  15.  
  16.     screen=ChooseScreen(screen,"Which screen?");
  17.     device=GetScreenDevice(screen);
  18.     savePict=Choose(savePict,"Save image to disk as a PICT file?\n",noYes,2);
  19.     saveEPS=Choose(saveEPS,"Save image to disk as an EPS file?\n",noYes,2);
  20.     // add code here to create your GWorld and put an interesting image in it.
  21.     ShowAndSaveGWorld(world,device,expand,"interesting",savePict,saveEPS);
  22.     DisposeGWorld(world);
  23.  
  24. HISTORY:
  25. 3/20/95 dgp wrote it to produce illustrations for Discover Magazine.
  26. 6/30/95 dgp added to the VideoToolbox, while I was preparing demos for my NIH application.
  27. */
  28. #include "VideoToolbox.h"
  29. void ShowAndSaveGWorld(GWorldPtr smallWorld,GDHandle device,double expand
  30.     ,char *filename,Boolean savePict,Boolean saveEPS);
  31.  
  32. void ShowAndSaveGWorld(GWorldPtr smallWorld,GDHandle device,double expand
  33.     ,char *filename,Boolean savePict,Boolean saveEPS)
  34. {
  35.     char string[100];
  36.     Rect pageRect,paperRect,r;
  37.     long copyMode;
  38.     WindowPtr window,oldPort;
  39.     ColorTable **ct;
  40.     int error;
  41.  
  42.     // show it
  43.     assert(device!=NULL);
  44.     assert(smallWorld!=NULL);
  45.     assert(IsGWorldPtr(smallWorld));
  46.     ct=(**GetGWorldPixMap(smallWorld)).pmTable;
  47.     assert(ct!=NULL);
  48.     error=GDSetEntriesByType(device,0,(**ct).ctSize,(**ct).ctTable);
  49.     window=GDOpenWindow1(device);
  50.     assert(window!=NULL);
  51.     r=smallWorld->portRect;
  52.     OffsetRect(&r,-r.left,-r.top);
  53.     SectRect(&r,&window->portRect,&r);
  54.     SizeWindow(window,r.right,r.bottom,0);
  55.     GetPort(&oldPort);
  56.     SetPort(window);
  57.     EraseRect(&window->portRect);
  58.     SetPort(oldPort);
  59.     if(GDPixelSize(device)==GDPixelSize(GetGWorldDevice(smallWorld)))copyMode=srcCopyLiterally;
  60.     else copyMode=srcCopy;
  61.     r=smallWorld->portRect;
  62.     CenterRectInRect(&r,&window->portRect);
  63.     error=CopyWindows(smallWorld,(CWindowPtr)window
  64.         ,&smallWorld->portRect,&r,copyMode,NULL);
  65.     if(error)PrintfExit("%s line %d: CopyWindows error %d\n",__FILE__,__LINE__,error);
  66.  
  67.     if(0){
  68.         // show it, bigger
  69.         r=smallWorld->portRect;
  70.         ExpandRect(&r,expand,expand);
  71.         printf("Hit return to continue.\n");
  72.         gets(string);
  73.         SizeWindow(window,r.right,r.bottom,1);
  74.         CenterRectInRect(&r,&window->portRect);
  75.         error=CopyWindows(smallWorld,(CWindowPtr)window,&smallWorld->portRect,&r,copyMode,NULL);
  76.         if(error)PrintfExit("%s line %d: CopyWindows error %d\n",__FILE__,__LINE__,error);
  77.     }
  78.  
  79.     if(savePict){
  80.         sprintf(string,"%s.pict",filename);
  81.         PixMapToPICT(string,smallWorld->portPixMap
  82.             ,&smallWorld->portRect,2,NULL);
  83.         printf("Image was saved to disk as file “%s”.\n",string);
  84.     }
  85.     if(saveEPS){
  86.         pageRect=smallWorld->portRect;
  87.         ExpandRect(&pageRect,expand,expand);
  88.         pageRect.top*=-1;        // convert from Apple to Adobe coordinates
  89.         pageRect.bottom*=-1;    // convert from Apple to Adobe coordinates
  90.         SetRect(&paperRect,0,11*72,8.5*72,0);
  91.         CenterRectInRect(&pageRect,&paperRect);
  92.         sprintf(string,"%s.eps",filename);
  93.         WindowToEPS(smallWorld,string,&smallWorld->portRect,&pageRect,0,0,NULL);
  94.         printf("Image was saved to disk as file “%s”.\n",string);
  95.     }
  96.     printf("Hit return to continue.\n");
  97.     gets(string);
  98.     GDDisposeWindow1(window);
  99.     RestoreDeviceClut(device);
  100. }